package bookManage.utils;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * @BelongsProject: library-management-system-master
 * @BelongsPackage: bookManage.Model.dao
 * @Author: yuan wang
 * @CreateTime: 2023-02-01  22:49
 * @Description: 获取前端传过来的json数据，并存储在StringBuilder返回中，借鉴了学长的工具类
 * @Version: 1.0
 */
public class JsonUtil {
    public static StringBuilder getJson(HttpServletRequest request) throws IOException {
        InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
        StringBuilder str = new StringBuilder();
        int respInt = inputStreamReader.read();
        while (respInt != -1) {
            str.append((char) respInt);
            respInt = inputStreamReader.read();
        }
        return str;
    }
}
